package com.atguigu.flume.interceptor;
import  org.apache.commons.lang.math.NumberUtils;

public class LogUtils {


    // 服务器时间 | json
    // 1549696569054 | {"cm":{"ln":"-89.2","sv":"V2.0.4","os":"8.2.0","g":"M67B4QYU@gmail.com","
    // nw":"4G","l":"en","vc":"18","hw":"1080*1920","ar":"MX","uid":"u8678","t":"
    // 1549679122062","la":"-27.4","md":"sumsung-12","vn":"1.1.3","ba":"Sumsung","sr":"Y
    // "},"ap":"weather","et":[]}

    public static boolean validateEvent(String log)  {
        // 切 =》 判断时间 数值，长度=13 =》json格式{}
        String[] split = log.split("\\|");
        if(split.length != 2 ){
            return  false ;
        }

        if(split[0].length() != 13 || ! NumberUtils.isDigits(split[0])    ){

            return  false ;
        }
        if( !split[1].startsWith("{")  || split[1].endsWith("}")  ){

            return  false  ;
        }
        return  true ;
    }

    //
    // {"action":"1","ar":"MX","ba":"HTC","detail":"542","en":"start","
    //
    // entry":"2","extend1":"","g":"S3HQ7LKM@gmail.com","hw":"640*960","l":"en",
    // "la":"-43.4","ln":"-98.3","loading_time":"10","md":"HTC-5","mid":"993","nw":"WIFI","open_ad_type":"1","os":"8.2.1","sr":"D","sv":"V2.9.0","t":"1559551922019","uid":"993","vc":"0","vn":"1.1.5"}


    public static boolean validateStart(String log) {
        // 切 =》 判断 空 ，=》json格式{}
        if (log == null){
            return false;
        }

        // 校验json
        if (!log.trim().startsWith("{") || !log.trim().endsWith("}")){
            return false;
        }

        return true;

    }


}
